//
// Created by summerday on 2021/6/4.
//
#include "cstdio"
#include "iostream"
#include "linked_stack.h"



// list = (LNode *) malloc(sizeof(LNode *));
void initStack(LinkStack &s) {
    s = NULL;
}

bool push(LinkStack &s, int x) {
    LinkNode *node = (LinkNode *) malloc(sizeof(LinkNode *));
    node->data = x;
    node->next = s;
    s = node;
    return true;
}

bool pop(LinkStack &s, int &x) {
    if (empty(s)){
        return false;
    }
    x = s->data;
    LinkNode *p = s;
    s = s->next;
    free(p);
    return true;
}

bool empty(LinkStack &s){
    return s == NULL;
}

bool getTop(LinkStack s, int &x) {
    if (empty(s))
        return false;
    x = s->data;
    return true;
}

void print(LinkStack s){
    if(empty(s)) {
        cout << "stack is empty now !" << endl;
        return;
    }
    LinkNode *p = s;
    cout << "---- top ----" << endl;
    while(p){
        cout << p->data << " ";
        p = p->next;
    }
    cout << endl;
    cout << "---- end ----" << endl;
}




